<template>
  <view>
    <view
      class="ss-flex ss-row-left ss-m-26 ss-p-20 ss-r-20 ss-bg-w1"
      v-for="(i, index) in list"
      :key="index"
      @click="handleDownload(i)"
    >
      <uv-icon :name="iconFile" size="80rpx" />
      <view class="ss-m-x-10 ss-black">
        <view class="ss-m-y-10 ss-font-28">{{ i.fileName || "--" }}</view>
        <view class="ss-m-y-10 ss-font-25 ss-grey-2">
          {{ i.createTime }} {{ i.createBy }}
        </view>
      </view>
    </view>
    <uv-empty
      v-if="list.length === 0"
      :customStyle="{ margin: '10vh auto' }"
      :icon="empty"
      text="暂无附件"
    />
  </view>
</template>

<script setup>
import { webSrc } from "@/common/mothed.js";
import iconFile from "@/static/order/icon_file2.png";
import empty from "@/static/empty.png";
const props = defineProps({
  list: {
    type: Array,
    default: () => [],
  },
});

// 下载文档
const handleDownload = (item) => {
  uni.downloadFile({
    url: webSrc(item.filePath),
    success: (res) => {
      const filePath = res.tempFilePath;
      uni.openDocument({
        filePath: filePath,
        success: (res) => {
          console.log("打开文档成功");
        },
      });
    },
  });
};
</script>

<style lang="scss" scoped>
@import "@/uni.scss";
</style>
